package com.ruoyi.web.controller.consume;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consume.domain.RegulatorApplyCon;
import com.ruoyi.consume.service.IRegulatorApplyConService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 调节剂领用Controller
 *
 * @author ruoyi
 * @date 2021-07-23
 */
@Api("调节剂领用")
@RestController
@RequestMapping("/consume/regulatorap")
public class RegulatorApplyConController extends BaseController
{
    @Autowired
    private IRegulatorApplyConService regulatorApplyService;

    /**
     * 查询调节剂领用列表
     */
    @ApiOperation("查询调节剂领用列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:regulatorap:list')")
    @GetMapping("/list")
    public TableDataInfo list(RegulatorApplyCon regulatorApplyCon)
    {
        startPage();
        List<RegulatorApplyCon> list = regulatorApplyService.selectRegulatorApplyList(regulatorApplyCon);
        return getDataTable(list);
    }

    /**
     * 导出调节剂领用列表
     */
    @PreAuthorize("@ss.hasPermi('consume:regulatorap:export')")
    @Log(title = "调节剂领用", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RegulatorApplyCon regulatorApplyCon)
    {
        List<RegulatorApplyCon> list = regulatorApplyService.selectRegulatorApplyList(regulatorApplyCon);
        ExcelUtil<RegulatorApplyCon> util = new ExcelUtil<RegulatorApplyCon>(RegulatorApplyCon.class);
        return util.exportExcel(list, "调节剂领用数据");
    }

    /**
     * 获取调节剂领用详细信息
     */
    @PreAuthorize("@ss.hasPermi('consume:regulatorap:query')")
    @GetMapping(value = "/{regulatorApplyId}")
    public AjaxResult getInfo(@PathVariable("regulatorApplyId") Long regulatorApplyId)
    {
        return AjaxResult.success(regulatorApplyService.selectRegulatorApplyById(regulatorApplyId));
    }

    /**
     * 新增调节剂领用
     */
    @PreAuthorize("@ss.hasPermi('consume:regulatorap:add')")
    @Log(title = "调节剂领用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RegulatorApplyCon regulatorApplyCon)
    {
        return toAjax(regulatorApplyService.insertRegulatorApply(regulatorApplyCon));
    }

    /**
     * 修改调节剂领用
     */
    @PreAuthorize("@ss.hasPermi('consume:regulatorap:edit')")
    @Log(title = "调节剂领用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RegulatorApplyCon regulatorApplyCon)
    {
        return toAjax(regulatorApplyService.updateRegulatorApply(regulatorApplyCon));
    }

    /**
     * 删除调节剂领用
     */
    @PreAuthorize("@ss.hasPermi('consume:regulatorap:remove')")
    @Log(title = "调节剂领用", businessType = BusinessType.DELETE)
	@DeleteMapping("/{regulatorApplyIds}")
    public AjaxResult remove(@PathVariable Long[] regulatorApplyIds)
    {
        return toAjax(regulatorApplyService.deleteRegulatorApplyByIds(regulatorApplyIds));
    }

    /**
     * 更新库存量表
     */
    @ApiOperation("更新库存量表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:regulatorap:amount')")
    @Log(title = "调节剂领用", businessType = BusinessType.UPDATE)
    @PutMapping("/amount")
    public AjaxResult amount(@RequestBody RegulatorApplyCon regulatorApplyCon)
    {
        return toAjax(regulatorApplyService.updateRegulatorAmount(regulatorApplyCon));
    }

    /**
     * 更新领用状态
     */
    @ApiOperation("更新领用状态")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:regulatorap:consu')")
    @Log(title = "调节剂领用", businessType = BusinessType.UPDATE)
    @PutMapping("/consu/{regulatorApplyId}")
    public AjaxResult consume(@PathVariable("regulatorApplyId") Long regulatorApplyId)
    {
        return toAjax(regulatorApplyService.updateConsumeStatus(regulatorApplyId));
    }

    /**
     * 退回操作
     */
    @ApiOperation("退回操作")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('consume:regulatorap:back')")
    @Log(title = "调节剂领用", businessType = BusinessType.UPDATE)
    @PutMapping("/back/{regulatorApplyId}")
    public AjaxResult back(@PathVariable("regulatorApplyId") Long regulatorApplyId)
    {
        return toAjax(regulatorApplyService.updateApprovalStatus(regulatorApplyId));
    }
}
